Program error trying to generate Outlook 2013 email from Visual Basic 2010 [on hold]

Posted by Dewayne Pinion on Programmers See other posts from Programmers or by Dewayne Pinion
Published on 2013-10-24T13:06:56Z Indexed on 2013/10/24 16:08 UTC
Read the original article Hit count: 384

I am using vb to send emails through outlook. Currently we have a mix of outlook versions at our office: 2010 and 2013 with a mix of 32 bit and 64 bit (a mess, I know). The code I have works well for Outlook 2010:

Private Sub btnEmail_Click(sender As System.Object, e As System.EventArgs) Handles btnEmail.Click
    CreateMailItem()
End Sub


Private Sub CreateMailItem()
    Dim application As New Application

    Dim mailItem As Microsoft.Office.Interop.Outlook.MailItem = CType(application.CreateItem( _
    Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), Microsoft.Office.Interop.Outlook.MailItem) 'Me.a(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
    mailItem.Subject = "This is the subject"
    mailItem.To = "[email protected]"
    mailItem.Body = "This is the message."
    mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow
    mailItem.Display(True)      

End Sub

However, I cannot get this to work for 2013. I have referenced the version 15 dll for 2013 and it seems to be backward compatible, but when I try to use the above code for 2013 (it is 64 bit) it says it cannot start Microsoft Outlook. A program error has occured. This is happening on the application Dim statement line. I have tried googling around but there doesn't seem to be much out there referencing 2013 but I feel that the problem here probably has more to do with 64 bit than the software version. Thank you for any suggestions!

© Programmers or respective owner

Related posts about visual-studio-2010

Related posts about visual-basic